package com.huatai.exchange.deal;

import com.alibaba.fastjson.JSON;
import com.faneui.common.exception.BusinessException;
import com.huatai.exchange.dal.model.ExcDataFileInfo;
import com.huatai.exchange.dal.model.ExcExchangeDateFile;
import com.huatai.exchange.facade.Contents;
import com.huatai.exchange.facade.FileSourceContents;
import com.huatai.exchange.utils.FileDealUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service("fileCreateLoadDealService")
public class FileCreateLoadDealServiceImpl extends AbstractFileCreateDealServiceImpl implements FileCreateDealService {

    @Override
    public void downloadCreateFile(StringBuffer fileNames, StringBuffer filePaths, ExcExchangeDateFile exchangeDateFile, ExcDataFileInfo dataFileInfo, Map<String, Object> resvMap) throws BusinessException {
        Map<String, Object> excDataFileMap = JSON.parseObject(exchangeDateFile.getProperties(), HashMap.class);
        Map<String, Object> valueMap = JSON.parseObject(dataFileInfo.getValue(), HashMap.class);
        String fileName = FileDealUtils.formatStr(dataFileInfo.getFileName(), excDataFileMap, resvMap);
        String loadFileId =  (String) valueMap.get(FileSourceContents.LOAD_FILE_ID);
        String occurDate = (String) resvMap.get(Contents.FIELD_YYYYMMDD);
        String filePath = excFileLoadRecordService.queryExcFileLoadPath(loadFileId, occurDate);
        if (StringUtils.isBlank(filePath)) {
            throw new BusinessException("文件未准备好");
        }
        fileNames.append("," + fileName);
        filePaths.append("," + filePath);
    }


}
